<?php
/**
 * 商品管理
 *
 * @category     Shuxun Cms
 * @date         2015年10月18日
 * @author       Shuxun Team <kaiping.jiang@scshux.com>
 * @file         GoodsController.php
 */
namespace Scshux\Backend\Controllers;
use Scshux\Mvc\SModel;
use Scshux\Mvc\SQuery;
use Scshux\Utils\Tree;
use Scshux\Utils\Time;
use Scshux\Utils\Uploader;
class GoodsController extends  ControllerBase
{

	/**
	 * 文章列表
	 */
	public  function indexAction()
	{
		$is_ajax  = $this->request->get('is_ajax','int',0);
		$act  = $this->request->get('act');
		if($act == 'remove'){
			$this->_removeGoods();
		}
		$dataList = $this->_getGoodsList();
		$this->view->setVar('dataList', $dataList);
		if($is_ajax){

			$this->view->setVar('full_page',0);
			$this->view->start();
			$this->view->render('goods','index');
			$this->view->finish();
			$content = $this->view->getContent();
			$data = array(
					'content' => $content,
					'filter'  => $dataList->filter,
					'totalPage' => $dataList->totalPage,
					'recordCount'=>$dataList->totalSize,
					'currentPage'=>$dataList->currentPage,
					'extended'   =>$dataList->extended
			);
			$this->sendResult(true,'',$data);
		}else{
			$this->view->setVar('categoryHtml', $this->getCategoriesHtml());
			$this->view->setVar('full_page',1);
		}
	}

	/**
	 * 文章操作
	 */
	public  function  editAction()
	{
		$id = $this->request->get('id','int',0);
		if($id<1){
			$id = $this->request->get('goods_id','int',0);
		}
		$id = intval($id);

		if($this->request->isPost()){
			//加入语言
			$_POST['site_id'] = $this->getCore()->getSiteID();

			$postData = $_POST;
			$postData['content'] = stripcslashes($postData['content']);
			$goodsModel = new SModel('goods');
		    $postData['goods_desc'] = stripcslashes($postData['goods_desc']);

		    //如果没得默认取第一张
		    if(empty($postData['goods_img'])){
		    	$postData['goods_img'] = $postData['pic'][0];
		    }

			if($id>0){
				$goodsModel->setData($postData);
				$goodsModel->update('goods_id='.$id);
			}else{
				$postData['add_time'] = Time::gmtime();
				unset($postData['goods_id']);
				$goodsModel->setData($postData);
				$goodsModel->add();
				$id = $goodsModel->getInsertID();
			}

			$config = $this->getDI()->get('config');

			//封面
			$goodsGalleryModel = new SModel('goods_gallery');
			$goodsGalleryModel->del('goods_id='.$id);
			foreach ($postData['pic'] as $pic)
			{
				$goodsGalleryModel->setData(array(
					'goods_id' => $id,
					'img_url'  => $pic,
					'img_desc' => ''
				),true);
				$goodsGalleryModel->add();
			}


			$this->redirect('goods');

		}else{

			if($id>0){

				$goodsModel = new SModel('goods');
				$item = $goodsModel->getObj('goods_id='.$id);
				$this->view->setVar('item', $item);

				$goodsGalleryModel = new SModel('goods_gallery');
				$imgitems = $goodsGalleryModel->query('goods_id='.$id);
				$this->view->setVar('imgitems', $imgitems);
			}
			$this->view->setVar('categoryHtml', $this->getCategoriesHtml());
		}
	}

	/**
	 * 帮助分类列表
	 */
	public function   category_listAction()
	{
		$is_ajax  = $this->request->get('is_ajax','int',0);
		$dataList = $this->_getCategoryDataList();
		$this->view->setVar('dataList', $dataList);
		if($is_ajax){
			$this->view->setVar('full_page',0);
			$this->view->start();
			$this->view->render('article','category_list');
			$this->view->finish();
			$content = $this->view->getContent();
			$data = array(
					'content' => $content,
					'filter'  => $dataList->filter,
					'totalPage' => $dataList->totalPage,
					'recordCount'=>$dataList->totalSize,
					'currentPage'=>$dataList->currentPage,
					'extended'   =>$dataList->extended
			);
			$this->sendResult(true,'',$data);
		}else{
			$this->view->setVar('full_page',1);
		}

	}

	/**
	 * 帮助分类编辑
	 */
	public function   category_editAction()
	{
		$id = $this->request->get('id','int',0);
		if($this->request->isPost()){
			$categoryModel = new SModel('category');
			//加入语言
			$_POST['site_id'] = $this->getCore()->getSiteID();
			$postData = $_POST;

			if($_FILES['pic'])
			{
				$uploader = new Uploader();
				$tempfile=$uploader->upload($_FILES['pic']);
				if($tempfile)
				{
					$postData['pic'] = $tempfile;
				}
			}

			if($id>0){
				$categoryModel->setData($postData);
				$categoryModel->update('id='.$id);
			}else{
				$postData['created'] = Time::gmtime();
				unset($postData['id']);
				$categoryModel->setData($postData);
				$categoryModel->add();
			}
			return $this->redirect('goods/category_list');
		}else{
			if($id>0){
				$categoryModel = new SModel('category');
				$item = $categoryModel->getObj('id='.$id);
				$this->view->setVar('item', $item);
				$this->view->setVar('categoryHtml', $this->getCategoriesHtml($item->parent_id,$id));
			}else{
				$this->view->setVar('categoryHtml', $this->getCategoriesHtml(0));
			}
		}
	}

	/**
	 * 删除分类
	 */
	public  function  category_delAction()
	{
		$id = $this->request->get('id','int',0);
		if($id>0){
			$categoryModel = new SModel('category');
			$categoryModel->del("id='{$id}' or parent_id='{$id}'");

			$categoryModel = new SModel('category');
			$categoryModel->del("id='{$id}'");
		}
		return $this->redirect('goods/category_list');
	}


	/**
	 * 装修风格
	 */
	public function zxstyleAction()
	{

	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removeZxstyle();
	    }
	    $dataList = $this->_getZxstyleList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','zxstyle');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }

	}



	/**
	 * 新增编辑装修风格信息
	 */
	public function zxstyleeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }
	        $gstyleModel = new SModel('goods_style');
	        $data = array(
	                'style_name'=>(string)$_POST['style_name'],
	        );
	        $gstyleModel ->setData($data);
	        if ($id)
	        {
	            $gstyleModel->update('id='.$id);
	        }
	        else
	        {
	            $gstyleModel->add();
	        }
	        return $this->redirect('goods/zxstyle');
	    }
	    else
	    {
	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('goods_style');
	        $item = $gstyleModel->getObj('id='.$id);
	        $this->view->setVar('item', $item);
	    }
	}


	/**
	 * 装修户型
	 */
	public function zxsizeAction()
	{
	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removeZxsize();
	    }
	    $dataList = $this->_getZxsizeList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','zxsize');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }
	}

	/**
	 * 装修户型编辑
	 */
	public function zxsizeeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }
	        $gstyleModel = new SModel('goods_roomsize');
	        $data = array(
	                'name'=>(string)$_POST['name'],
	        );
	        $gstyleModel ->setData($data);
	        if ($id)
	        {
	            $gstyleModel->update('id='.$id);
	        }
	        else
	        {
	            $gstyleModel->add();
	        }
	        return $this->redirect('goods/zxsize');
	    }
	    else
	    {
	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('goods_roomsize');
	        $item = $gstyleModel->getObj('id='.$id);
	        $this->view->setVar('item', $item);
	    }
	}


	/**
	 * 装修面积
	 */
	public function zxareaAction()
	{
	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removeZxarea();
	    }
	    $dataList = $this->_getZxareaList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','zxarea');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }
	}


	/**
	 * 装修户型编辑
	 */
	public function zxareaeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }
	        $gstyleModel = new SModel('goods_roomarea');
	        $data = array(
	                'name'=>(string)$_POST['name'],
	        );
	        $gstyleModel ->setData($data);
	        if ($id)
	        {
	            $gstyleModel->update('id='.$id);
	        }
	        else
	        {
	            $gstyleModel->add();
	        }
	        return $this->redirect('goods/zxarea');
	    }
	    else
	    {
	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('goods_roomarea');
	        $item = $gstyleModel->getObj('id='.$id);
	        $this->view->setVar('item', $item);
	    }
	}



	/**
	 * 装修造价
	 */
	public function zxpriceAction()
	{
	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removeZxprice();
	    }
	    $dataList = $this->_getZxpriceList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','zxprice');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }
	}



	/**
	 * 装修造价编辑
	 */
	public function zxpriceeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }
	        $gstyleModel = new SModel('goods_roomprice');
	        $data = array(
	                'name'=>(string)$_POST['name'],
	        );
	        $gstyleModel ->setData($data);
	        if ($id)
	        {
	            $gstyleModel->update('id='.$id);
	        }
	        else
	        {
	            $gstyleModel->add();
	        }
	        return $this->redirect('goods/zxprice');
	    }
	    else
	    {
	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('goods_roomprice');
	        $item = $gstyleModel->getObj('id='.$id);
	        $this->view->setVar('item', $item);
	    }
	}


	/**
	 * 设计师
	 */
	public function designerAction()
	{
	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removedesigner();
	    }
	    $dataList = $this->_getdesignerList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','designer');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }
	}


	/**
	 * 添加设计师
	 */
	public function designeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }
	        $gstyleModel = new SModel('designer');
	        $data = array(
	                'name'=>(string)$_POST['name'],
	                'type'=>intval($_POST['type']),
	                'level'=>(string)$_POST['level'],
	                'department'=>(string)$_POST['department'],
	                'univserity'=>(string)$_POST['univserity'],
	                'idea'=>(string)$_POST['idea'],
	                'year'=>intval($_POST['year']),
	        );
	        if ($_POST['style'])
	        {
	            $data['perstyle'] = join(',', $_POST['style']);
	        }
	        //图片
	        if($_FILES['head_ico']){
	            $uploaderObj = new Uploader();
	            $data['head_ico'] = $uploaderObj->upload($_FILES['head_ico']);
	            if(empty($data['head_ico'] )){
	                unset($data['head_ico'] );
	            }
	        }
	        $gstyleModel ->setData($data);
	        if ($id)
	        {
	            $gstyleModel->update('id='.$id);
	        }
	        else
	        {

	            $gstyleModel->add();
	        }
	        return $this->redirect('goods/designer');
	    }
	    else
	    {
	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('designer');
	        $item = $gstyleModel->getObj('id='.$id);
	        $zxstyleModel = new SModel('goods_style');

	        $zxStyle = $zxstyleModel->query(false,'*','id');

	        $this->view->setVar('zxstyle',$zxStyle);

	        $this->view->setVar('item', $item);
	    }
	}



	/**
	 * 案例列表
	 */
	public function caselistAction()
	{
	    $is_ajax  = $this->request->get('is_ajax','int',0);
	    $act  = $this->request->get('act');
	    if($act == 'remove'){
	        $this->_removecaselist();
	    }
	    $dataList = $this->_getcaseList();
	    $this->view->setVar('dataList', $dataList);
	    if($is_ajax){

	        $this->view->setVar('full_page',0);
	        $this->view->start();
	        $this->view->render('goods','caselist');
	        $this->view->finish();
	        $content = $this->view->getContent();
	        $data = array(
	                'content' => $content,
	                'filter'  => $dataList->filter,
	                'totalPage' => $dataList->totalPage,
	                'recordCount'=>$dataList->totalSize,
	                'currentPage'=>$dataList->currentPage,
	        );
	        $this->sendResult(true,'',$data);
	    }else{
	        $this->view->setVar('full_page',1);
	    }
	}



	/**
	 * 增加编辑案例
	 */
	public function caseeditAction()
	{
	    if ($this->request->isPost())
	    {
	        $id = isset($_POST['id']) && !empty($_POST['id']) ? intval($_POST['id']): '';
	        if ($id)
	        {
	            unset($_POST['id']);
	        }

	        $postData = array(
	                'name'=>(string)$_POST['name'],
	                'style'=>intval($_POST['style']),
	                'size'=>intval($_POST['size']),
	                'cat_id'=>intval($_POST['cat_id']),
	                'price'=>floatval($_POST['price']),
	                'price_group'=>intval($_POST['price_group']),
	                'area'=>floatval($_POST['area']),
	                'area_group'=>intval($_POST['area_group']),
	                'desc'=>(string)$_POST['desc'],
	                'design_id'=>intval($_POST['design_id']),
	        );
	        //封面图
	        if($_FILES['img']){
	            $uploaderObj = new Uploader();
	            $postData['img'] = $uploaderObj->upload($_FILES['img']);
	            if(empty($postData['img'] )){
	                unset($postData['img'] );
	            }
	        }

	        $caseModel = new SModel('cases');
	        $caseModel->setData($postData);
	        if($id>0){
	            $caseModel->update('id='.$id);
	        }else{

	            $caseModel->add();
	            $id = $caseModel->getInsertID();
	        }


	        //相册
	        $goodsGalleryModel = new SModel('goods_gallery');
	        $goodsGalleryModel->del('goods_id='.$id);
	        foreach ($_POST['pic'] as $pic)
	        {
	            $goodsGalleryModel->setData(array(
	                    'goods_id' => $id,
	                    'img_url'  => $pic,
	                    'img_desc' => ''
	            ),true);
	            $goodsGalleryModel->add();
	        }
	        return $this->redirect('goods/caselist');
	    }
	    else
	    {

	        $id = isset($_GET['id']) && !empty($_GET['id']) ? intval($_GET['id']): 0;
	        if ($id)
	        {
	            unset($_GET['id']);
	        }
	        $gstyleModel = new SModel('cases');
	        $item = $gstyleModel->getObj('id='.$id);

	        $zxstyleModel = new SModel('goods_style');
	        $zxStyle = $zxstyleModel->query(false,'*','id');

	        $zxsizeModel = new SModel('goods_roomsize');
	        $zxsize = $zxsizeModel->query(false,'*','id');

	        $zxareaModel = new SModel('goods_roomarea');
	        $zxarea = $zxareaModel->query(false,'*','id');

	        $zxpriceModel = new SModel('goods_roomprice');
	        $zxprice = $zxpriceModel->query(false,'*','id');

	        $designModel = new SModel('designer');
	        $design = $designModel->query(false,'id,name','id');


	        $goodsGalleryModel = new SModel('goods_gallery');
	        $imgitems = $goodsGalleryModel->query('goods_id='.$id);
	        $this->view->setVar('imgitems', $imgitems);





	        $this->view->setVar('zxstyle',$zxStyle);
	        $this->view->setVar('zxsize',$zxsize);
	        $this->view->setVar('zxarea',$zxarea);
	        $this->view->setVar('zxprice',$zxprice);
	        $this->view->setVar('designer',$design);
	        $this->view->setVar('item', $item);

	    }
	}


	/**
	 * 删除信息
	 */
	protected  function _removeGoods()
	{
		$id = $this->request->get('id','int',0);
		$goodsModel = new SModel('goods');
		$goodsModel->del('goods_id='.$id);
	}

	/**
	 * 删除装修风格
	 */
	private function _removeZxstyle()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('goods_style');
	    $goodsModel->del('id='.$id);
	}

	/**
	 * 删除装修户型
	 */
	private function _removeZxsize()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('goods_roomsize');
	    $goodsModel->del('id='.$id);
	}


	/**
	 * 删除装修面积
	 */
	private function _removeZxarea()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('goods_roomarea');
	    $goodsModel->del('id='.$id);
	}


	/**
	 * 删除装修造价
	 */
	private function _removeZxprice()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('goods_roomprice');
	    $goodsModel->del('id='.$id);
	}


	/**
	 * 删除设计师
	 */
	public function _removedesigner()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('designer');
	    $goodsModel->del('id='.$id);
	}


	/**
	 * 删除案例
	 */
	public function _removecaselist()
	{
	    $id = $this->request->get('id','int',0);
	    $goodsModel = new SModel('cases');
	    $goodsModel->del('id='.$id);
	}



  /**
   * 获取用户信息
   */
   protected  function _getGoodsList()
   {
	   	$filter = array();

	   	$page = $this->request->get('page','int',1);

	   	$where = '1=1';
	   	//新增语言过滤
	   	$site_id = $this->getCore()->getSiteID();
	   	$where .= ' and g.site_id = '.$site_id;

	   	if(!empty($_REQUEST['keywords'])){
	   		$where = 'g.`goods_name` like "%'.$_REQUEST['keywords'].'%"';
	   		$filter['keywords'] = $_REQUEST['keywords'];
	   	}

	   	if(!empty($_REQUEST['cat_id'])){

	   		$cid = intval($_REQUEST['cat_id']);
	   		//读取所有分类
	   		$goodsCategoryModel = new SModel('category');
	   		$goodsCategoryModel->setFetchMode(\PDO::FETCH_ASSOC);
	   		$goodsCategories = $goodsCategoryModel->query('site_id='.$site_id,'*','sort desc,id','desc');
	   		$treeObj = new Tree($goodsCategories);
	   		$childIds = $treeObj->getChilds($cid);
	   		$childIds[] = $cid;
	   		$where = 'g.cat_id in('.join(',', $childIds).')';
	   		$filter['cat_id'] = $_REQUEST['cat_id'];

	   	}

	   	$helpQuery = new SQuery('goods as g');
	   	$helpQuery->join = ' left join category as c on g.cat_id=c.id';
	   	$helpQuery->fields = 'g.*,c.name as cat_name';
	   	$helpQuery->page =  $page;
	   	$helpQuery->where = $where;
	   	$helpQuery->order = 'g.goods_id desc';
	   	$helpQuery->pagesize = 12;

	   	$items = $helpQuery->find();

	   	$dataList = new \stdClass();
	   	$dataList->totalPage = $helpQuery->paging->getTotalPage();
	   	$dataList->currentPage = $helpQuery->paging->getIndex();
	   	$dataList->items = $items;
	   	$dataList->totalSize = $helpQuery->paging->getTotalSize();
	   	$dataList->filter = $filter;

	   	return  $dataList;
   }


	/**
	 * 分类列表数据
	 */
	protected   function  _getCategoryDataList()
	{
		$filter = array();
		$items = $this->getCategoriesTree();
		foreach ($items as $key => $item)
		{
			$items[$key] = (object)$item;
		}
		$dataList = new \stdClass();
		$dataList->totalPage = 1;
		$dataList->currentPage = 1;
		$dataList->items = $items;
		$dataList->totalSize = count($items);
		$dataList->filter = $filter;
		return  $dataList;
	}

	/**
	 * 获取所有分类html
	 */
	protected  function  getCategoriesHtml($id = 0,$outId=0)
	{
		$categoryModel = new SModel('category as c');
		$categoryModel->setFetchMode(\PDO::FETCH_ASSOC);

		//新增语言过滤
		$site_id = $this->getCore()->getSiteID();
		$where = ' c.site_id = '.$site_id;

		$items = $categoryModel->query($where,'*','c.sort desc,c.id','DESC');
	    $treeObj = new Tree($items);
	    return  $treeObj->getHtmlOptions($id,$outId);
	}


	/**
	 * 获取所有分类树
	 */
	protected  function  getCategoriesTree($id = 0)
	{
		$categoryModel = new SModel('category as c');
		$categoryModel->setFetchMode(\PDO::FETCH_ASSOC);

		//新增语言过滤
		$site_id = $this->getCore()->getSiteID();
		$where = ' c.site_id = '.$site_id;

		$items = $categoryModel->query($where,'*','c.sort desc,c.id','DESC');
		$treeObj = new Tree($items);
		return  $treeObj->unlimitedForLevel('&nbsp;&nbsp;',$id);
	}

	/**
	 * 装修风格
	 */
	private function _getZxstyleList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('goods_style as gs');
	    $helpQuery->fields = 'gs.*';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();

	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}

	/**
	 * 装修户型
	 */
	private function _getZxsizeList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('goods_roomsize as gs');
	    $helpQuery->fields = 'gs.*';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();

	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}

	/**
	 * 装修面积
	 */
	public function _getZxareaList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('goods_roomarea as gs');
	    $helpQuery->fields = 'gs.*';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();

	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}


	/**
	 * 装修造价
	 */
	private function _getZxpriceList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('goods_roomprice as gs');
	    $helpQuery->fields = 'gs.*';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();

	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}


	public function _getdesignerList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('designer as gs');
	    $helpQuery->fields = 'gs.*';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();

	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}

	/**
	 * 案例列表
	 */
	private function _getcaseList()
	{
	    $filter = array();

	    $page = $this->request->get('page','int',1);

	    $where = '1=1';


	    $helpQuery = new SQuery('cases as gs');
	    $helpQuery->fields = 'gs.*,ds.name as dsname,s.style_name';
	    $helpQuery->join = ' join designer as ds on ds.id=gs.design_id  join goods_style as s on s.id=gs.style ';
	    $helpQuery->page =  $page;
	    $helpQuery->where = $where;
	    $helpQuery->order = 'gs.id desc';
	    $helpQuery->pagesize = 12;

	    $items = $helpQuery->find();
	    $dataList = new \stdClass();
	    $dataList->totalPage = $helpQuery->paging->getTotalPage();
	    $dataList->currentPage = $helpQuery->paging->getIndex();
	    $dataList->items = $items;
	    $dataList->totalSize = $helpQuery->paging->getTotalSize();
	    $dataList->filter = $filter;

	    return  $dataList;
	}

}